package com.whl.sm.service.impl.assets;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whl.sm.mapper.assets.ComBuildingMapper;
import com.whl.sm.model.assets.ComBuilding;
import com.whl.sm.model.system.OrgUser;
import com.whl.sm.service.assets.ComBuildingService;
import com.whl.sm.service.system.OrgUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuhaolun
 * @since 2021-10-09
 */
@Service
public class ComBuildingServiceImpl extends ServiceImpl<ComBuildingMapper, ComBuilding> implements ComBuildingService {

    @Autowired
    private OrgUserService orgUserService;


    @Override
    @Transactional(propagation= Propagation.REQUIRED)
    public int update(ComBuilding building) {
        int result;
        building.setOperator(orgUserService.getCurrentUserId());
        if (StringUtils.isNotBlank(building.getId())){
            getBaseMapper().updateById(building);
            result=1;
        }
        else {
            getBaseMapper().insert(building);
            result=2;
        }
        return result;

    }
}
